package com.philips.servlet;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;

import com.alibaba.fastjson.JSON;
import com.philips.service.AQIService;
import com.philips.service.AirService;

public class AirServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String msg;
		String dataRootPath=req.getRealPath("/")+"airdata/";
		try {
//			String urlaqi = "http://ixuanwu.com.cn/book/AQI/citys.php";
//			HttpClient client = new HttpClient();
//			GetMethod getaqi = new GetMethod(urlaqi);
//			getaqi.addRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");// 在头文件中设置转码
//			client.executeMethod(getaqi);
//			String airjson = new String(getaqi.getResponseBodyAsString().getBytes("utf-8"));
//			AirService as=new AirService();
//			String airjson =AirService.readFile("c:/temp/data.txt");
//			msg = as.saveAir(airjson,"shanghai");
			
			msg=AQIService.exportAQI("shanghai");
			
		} catch (Exception e) {
			msg=e.getMessage();
		}
		resp.getWriter().print(msg);
	}

}
